package com.yenlien.traceyun.usercenter.entity;

import com.yenlien.traceyun.webase.entity.BaseEntity;

import javax.persistence.*;
import java.lang.reflect.Field;
import java.util.List;

/**
 * @author: bigwangy@sina.com
 * @create: 2020-03-03
 * @description: 企业资料
 **/
@Entity
@Table(name = "t_company")
public class CompanyOrigin extends BaseEntity {
    @Column(name = "name", length = 50)
    private String name; //企业名称
    @Column(name = "abbreviation", length = 50)
    private String abbreviation;    //企业简称


    @Column(name = "area", length = 100)
    private String area;     //区域
    @Column(name = "credit_code", length = 18)    //统一社会代码
    private String creditCode;
    @Column(name = "address", length = 100)
    private String address;    //注册地址
    @Column(name = "term", length = 100)
    private String term;//经营期限

    @Column(name = "region", length = 100)
    private String region;

    /**
     * 父企业
     */
    @Column(name = "parent_id", length = 32)
    private String parentId;

    /**
     * 父企业名称
     */
    @Column(name = "parent_name", length = 100)
    private String parentName;

    @Column(name = "app_id", length = 100)
    private String appId;           //关联的平台

    @Column(length = 200)
    private String licenseImg; //公司执照
    @Column
    private String legalName;//法定代表人
    @Column
    private String legalPhone;//法定人电话
    @Column
    private String legalTime;//法定人证件期限
    @Column
    private String legalID;//法定人身份证
    @Column
    private String legalImg;//法定人身份证头像
    @Column
    private String legalIDImg;//法定人身份证背面
    @Column
    private String operateName;//运营代表人
    @Column
    private String operatePhone;//运营人电话
    @Column
    private String operateTime;//运营人证件期限
    @Column
    private String operateID;//运营人身份证
    @Column
    private String operateImg;//运营人身份证头像
    @Column
    private String operateIDImg;//运营人身份证背面
    @Column(length = 20)
    private String liaisonName;    //企业联系人
    @Column(name = "phone", length = 14)
    private String phone;    //企业联系电话号码
    @Column
    @Lob
    private String introduce;   //企业介绍
    @Column
    private String coverImg;   //企业封面
    @Column
    private String remark; //摘要，备注
    @Column(name = "createtime")
    private String createtime;   //创建时间
    @Column(name = "examined", length = 1)
    private String examined;     //审核通过 0驳回，1通过
    @Column(name = "expiretime")
    private String expiretime;     //过期时间

    @Column(name = "expiretime_end")
    private String expiretimeEnd;//过期结束时间

    @Column(name = "user_id")
    private String userId;     //绑定的用户id
    @Column
    private String type;    //1企业 2 政府 3代理商,0系统内置
    @Column
    private int state; //0有效数据；1无效数据
    @Column
    private String logoImg; //长方形企业log
    @Column
    private String logozImg; //正方形企业log

    @Column(name = "operatePosition", length = 50)
    private String operatePosition;       //职位

    @Column(name = "platform", length = 60)
    private String platform; //平台名字

    /**
     * 扫码log
     */
    @Column(name = "scan_img", length = 100)
    private String scanImg;

    @Transient
    private List<OtherMaterial> materialList;//证件证书集合
    @Transient
    private String materials;//证件证书前端传入时已字符串传入
    @Transient
    private User us;//用户
    @Transient
    private String user;//用户前端传入时已字符串传入
    @Transient
    private List<CompanyCustomAppVersion> versions;//企业应用
    @Transient
    private String versionsString;//用户前端传入时已字符串传入


    public String getOperatePosition() {
        return operatePosition;
    }

    public void setOperatePosition(String operatePosition) {
        this.operatePosition = operatePosition;
    }

    public String getPlatform() {
        return platform;
    }

    public void setPlatform(String platform) {
        this.platform = platform;
    }

    public String getLogoImg() {
        return logoImg;
    }

    public void setLogoImg(String logoImg) {
        this.logoImg = logoImg;
    }

    public String getLogozImg() {
        return logozImg;
    }

    public void setLogozImg(String logozImg) {
        this.logozImg = logozImg;
    }

    public String getVersionsString() {
        return versionsString;
    }

    public void setVersionsString(String versionsString) {
        this.versionsString = versionsString;
    }

    public List<CompanyCustomAppVersion> getVersions() {
        return versions;
    }

    public void setVersions(List<CompanyCustomAppVersion> versions) {
        this.versions = versions;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public User getUs() {
        return us;
    }

    public void setUs(User us) {
        this.us = us;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getCreatetime() {
        return createtime;
    }

    public void setCreatetime(String createtime) {
        this.createtime = createtime;
    }

    public String getExpiretime() {
        return expiretime;
    }

    public void setExpiretime(String expiretime) {
        this.expiretime = expiretime;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAbbreviation() {
        return abbreviation;
    }

    public void setAbbreviation(String abbreviation) {
        this.abbreviation = abbreviation;
    }

    public String getArea() {
        return area;
    }

    public void setArea(String area) {
        this.area = area;
    }

    public String getCreditCode() {
        return creditCode;
    }

    public void setCreditCode(String creditCode) {
        this.creditCode = creditCode;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getTerm() {
        return term;
    }

    public void setTerm(String term) {
        this.term = term;
    }

    public String getLicenseImg() {
        return licenseImg;
    }

    public void setLicenseImg(String licenseImg) {
        this.licenseImg = licenseImg;
    }

    public String getLegalName() {
        return legalName;
    }

    public void setLegalName(String legalName) {
        this.legalName = legalName;
    }

    public String getLegalPhone() {
        return legalPhone;
    }

    public void setLegalPhone(String legalPhone) {
        this.legalPhone = legalPhone;
    }

    public String getLegalTime() {
        return legalTime;
    }

    public void setLegalTime(String legalTime) {
        this.legalTime = legalTime;
    }

    public String getLegalID() {
        return legalID;
    }

    public void setLegalID(String legalID) {
        this.legalID = legalID;
    }

    public String getLegalImg() {
        return legalImg;
    }

    public void setLegalImg(String legalImg) {
        this.legalImg = legalImg;
    }

    public String getLegalIDImg() {
        return legalIDImg;
    }

    public void setLegalIDImg(String legalIDImg) {
        this.legalIDImg = legalIDImg;
    }

    public String getOperateName() {
        return operateName;
    }

    public void setOperateName(String operateName) {
        this.operateName = operateName;
    }

    public String getOperatePhone() {
        return operatePhone;
    }

    public void setOperatePhone(String operatePhone) {
        this.operatePhone = operatePhone;
    }

    public String getOperateTime() {
        return operateTime;
    }

    public void setOperateTime(String operateTime) {
        this.operateTime = operateTime;
    }

    public String getOperateID() {
        return operateID;
    }

    public void setOperateID(String operateID) {
        this.operateID = operateID;
    }

    public String getOperateImg() {
        return operateImg;
    }

    public void setOperateImg(String operateImg) {
        this.operateImg = operateImg;
    }

    public String getOperateIDImg() {
        return operateIDImg;
    }

    public void setOperateIDImg(String operateIDImg) {
        this.operateIDImg = operateIDImg;
    }

    public String getLiaisonName() {
        return liaisonName;
    }

    public void setLiaisonName(String liaisonName) {
        this.liaisonName = liaisonName;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getIntroduce() {
        return introduce;
    }

    public void setIntroduce(String introduce) {
        this.introduce = introduce;
    }

    public String getCoverImg() {
        return coverImg;
    }

    public void setCoverImg(String coverImg) {
        this.coverImg = coverImg;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getExamined() {
        return examined;
    }

    public void setExamined(String examined) {
        this.examined = examined;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public List<OtherMaterial> getMaterialList() {
        return materialList;
    }

    public void setMaterialList(List<OtherMaterial> materialList) {
        this.materialList = materialList;
    }

    public String getMaterials() {
        return materials;
    }

    public void setMaterials(String materials) {
        this.materials = materials;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public String getParentName() {
        return parentName;
    }

    public void setParentName(String parentName) {
        this.parentName = parentName;
    }

    public String getScanImg() {
        return scanImg;
    }

    public void setScanImg(String scanImg) {
        this.scanImg = scanImg;
    }

    public String getExpiretimeEnd() {
        return expiretimeEnd;
    }

    public String getRegion() {
        return region;
    }

    public void setRegion(String region) {
        this.region = region;
    }


    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public void setExpiretimeEnd(String expiretimeEnd) {
        this.expiretimeEnd = expiretimeEnd;
    }

    public void setImgName(String originalFilename, String newName) throws IllegalAccessException {
        Field[] fields = this.getClass().getDeclaredFields();
        for (Field field : fields) {
            if (field.getName().endsWith("Img")) {
                field.setAccessible(true);
                String value = (String) field.get(this);
                if (value != null && value.contains(originalFilename)) {
                    field.set(this, value.replace(originalFilename, newName));
                    return;
                }
            }
        }
        if (this.getMaterialList() != null && this.getMaterialList().size() > 0) {
            for (OtherMaterial o : this.getMaterialList()) {
                if (o.getMaterialImg() != null && o.getMaterialImg().contains(originalFilename)) {
                    o.setMaterialImg(o.getMaterialImg().replace(originalFilename, newName));
                    return;
                }
            }
        }

    }

}
